# == Schema Information
#
# Table name: users
#
#  id            :integer          not null, primary key
#  name          :string
#  username      :string
#  password      :string
#  active        :boolean
#  last_login_at :datetime
#  created_at    :datetime         not null
#  updated_at    :datetime         not null
#

class User < ApplicationRecord
  scope :active, -> { where(active: true) }

  def password=(pwd)
    super Digest::MD5.hexdigest(pwd)
  end

  def self.valid_user(params)
    self.active.where(username: params[:username], password: Digest::MD5.hexdigest(params[:password])).first
  end
end
